package main

import (
	"net"
	"fmt"
	"os"
	"time"
)

func main() {
	endRunning := make(chan bool, 1)

	host := "localhost:4321"
	listener, err := net.Listen("tcp", host)

	if err != nil {
		endRunning <- true
		return
	}

	for {
		conn, err := listener.Accept()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error: %s", err)
			continue
		}
		go handleCient(conn)
	}

	<-endRunning
}

func handleCient(conn net.Conn) {
	defer conn.Close()

	daytime := time.Now().String()
	println("connect on :" + daytime)

	//conn.Write([]byte())

	requestData := make([]byte, 1024)
	conn.Read(requestData)

	println(string(requestData))
}
